package cn.com.shinho.hg.auth.modular.service.impl;

import cn.com.shinho.hg.auth.modular.entity.TbSysOperate;
import cn.com.shinho.hg.auth.modular.service.ISysPermissionService;
import cn.com.shinho.hg.auth.modular.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 资源表 服务实现类
 * </p>
 *
 * @author Mr.Ye
 * @since 2018-07-09
 */
@Service
public class SysPermissionServiceImpl implements ISysPermissionService {

    @Autowired
    ISysRoleService sysRoleService;
    @Autowired
    ISysPermissionService sysPermissionService;

    @Override
    public Set<String> getPermissionUrlsByUserId(Long userId) {
        HashSet<String> permUrls = new HashSet<>();
        //查询用户的所有角色
        List<Long> sysUserRoles = sysRoleService.getUserRoleByUserId(userId);
        //遍历角色,获取所有角色的权限
        for (Long roleId : sysUserRoles) {
            List<TbSysOperate> sysPermisionsByRole = sysRoleService.getSysPermisionsByRole(roleId);
            for (TbSysOperate sysPermission : sysPermisionsByRole) {
                String url = sysPermission.getUrl();
                permUrls.add(url);
            }
        }
        return permUrls;
    }
}
